package com.smalldoor.thread.demo01;

//多个线程处理同一个数据的时候会出现线程安全
public class Thread04 implements Runnable{

    private int count = 30;
    @Override
    public void run() {
        while (true) {
            if (count <= 0) {
                break;
            }

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "拿到了第" + count-- + "张票");
        }
    }

    public static void main(String[] args) {
        Thread04 t1 = new Thread04();

        new Thread(t1,"张三").start();
        new Thread(t1,"李四").start();
        new Thread(t1,"王五").start();
        new Thread(t1,"赵六").start();
        new Thread(t1,"孙七").start();
    }
}
